package com.bw.interceptor;

import org.spring.kun.common.JwtUtils;
import org.spring.kun.common.TokenUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String token = TokenUtils.getTokenFromRequest(request);
        boolean flag = JwtUtils.validToken(token);
        if (!flag) {
            response.sendRedirect("/loginPage.do");
            return false;
        }


        return HandlerInterceptor.super.preHandle(request, response, handler);
    }
}
